import 'package:ad_plugin/ad_error.dart';
import 'package:ad_plugin/ad_listener.dart';
import 'package:ad_plugin/banner_ad.dart';
import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart' as google;
/// FileName banner_ad
/// @Author zhuqingfang
/// @Date 2022/10/8 4:42 下午
/// @Description banner ad
class BannerAdvertisement {
  BannerAdvertisement._internal();

  static final BannerAdvertisement _instance = BannerAdvertisement._internal();

  factory BannerAdvertisement() => _instance;
  BannerAd? _bannerAd;
  google.AdWidget? adWidget;

  void load() {

    BannerAd.load(
        placementId: 'b6341370f4257b',
        width: 350,
        height: 50,
        adLoadCallback: AdLoadCallback(
            onAdLoaded: (BannerAd bannerAd) {
              _bannerAd = bannerAd;
              // adWidget = google.AdWidget(ad:_bannerAd);
              debugPrint('banner ad load error');
              _bannerAd?.contentCallback = ContentCallback(
                  onAdShow: (BannerAd bannerAd) {
                    debugPrint('banner ad onShow');
                  },
                  onAdDismiss: (BannerAd bannerAd) {
                    debugPrint('banner ad onDismiss');
                  },
                  onAdClick: (BannerAd bannerAd) {
                    debugPrint('banner ad onClick');
                  });
            },
            onAdFailLoad: (BannerAd bannerAd,LoadAdError adError) {
              debugPrint('banner ad load error $adError');
            }));
  }
}
